package week05.question10;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public class HikariDataSourceUtils {

    private static final DataSource dataSource;

    static{
        HikariConfig config = new HikariConfig();
        config.setUsername("root");
        config.setPassword("123456");
        config.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai");
        config.setMaximumPoolSize(10);
        config.setMinimumIdle(5);
        config.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource = new HikariDataSource(config);
    }

    public static Connection getConnection() throws SQLException {
        return dataSource.getConnection();
    }
}
